package cn.tj.mapper;

import cn.tj.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface NormalMapper {
    /**
     * 获取客户列表
     * @return
     */
    @Select("select * from client")
    List<Client> ClientList();

    /**
     * 获取技师列表
     * @return
     */
    @Select("select * from Technician")
    List<Technician> TechnicianList();

    /**
     * 通过id获取房间详情
     * @param id
     * @return
     */
    @Select("select * from room " +
            "where id = #{id}")
    Room getRoomById(Integer id);

    /**
     * 开房
     * @param room
     */
    @Update("update room set " +
            "client_id=#{clientId},technician_id=#{technicianId},create_time=now()" +
            "where id = #{id}")
    void openRoom(Room room);

    /**
     * 退房，对房间信息进行重置
     * @param id
     */
    @Update("update room set " +
            "client_id = null,technician_id=null,create_time=null,money=0 " +
            "where id = #{id}")
    void offRoom(Integer id);

    /**
     * 获取食物列表
     * @return
     */
    @Select("select * from food")
    List<Food> foodList();

    /**
     * 新增食物订单
     * @param roomId
     * @param foodId
     */
    @Insert("insert into food_order " +
            "values (null,#{foodId},#{roomId})")
    void addFoodOrder(Integer roomId, Integer foodId);

    /**
     * 获取技师单价
     * @param technicianId
     * @return
     */
    @Select("select money from type " +
            "where id = (select type_id from technician where id = #{technicianId})")
    Double getTechnicianPrice(Integer technicianId);

    /**
     * 通过房间获取该房间食物总价
     * @param id
     * @return
     */
    Double getFoodSumPrice(Integer id);

    /**
     * 修改房间消费金额
     * @param id
     * @param money
     */
    @Update("update room set " +
            "money = #{money} " +
            "where id = #{id}")
    void editMoney(Integer id, Double money);

    /**
     * 根据房间id清空食物单的相关数据
     * @param id
     */
    @Delete("delete from food_order " +
            "where room_id = #{id}")
    void clearFoodOrderByRid(Integer id);

    /**
     * 结账，给技师计入业绩
     * @param hours
     * @param technicianMoney
     */
    @Update("update technician set " +
            "work_hours=work_hours+#{hours} , salary=salary+#{technicianMoney} " +
            "where id=#{id}")
    void editTechnician(Integer id, Long hours, double technicianMoney);

    /**
     * 用户余额扣款
     * @param clientId
     * @param money
     */
    @Update("update client set " +
            "money = money-#{money} " +
            "where id = #{clientId}")
    void editClientMoney(Integer clientId, Double money);

    /**
     * 新增订单
     * @param order
     */
    @Insert("insert into `order` " +
            "values (null,#{clientId},#{technicianId},#{money},now())")
    void addOrder(Order order);

    /**
     * 通过客户id查询客户信息
     * @param clientId
     * @return
     */
    @Select("select * from client where id =#{clientId}")
    Client getClientById(Integer clientId);

    /**
     * 通过房间id查询所下单的食物
     * @param id
     * @return
     */
    List<GetFoodsByRid> getFoodsByRid(Integer id);

    /**
     * 通过条件查询客户信息
     * @param name 姓名
     * @param vip 是否会员
     * @return
     */
    List<Client> ClientListByPage(String name, Integer vip);

    /**
     * 根据id删除客户信息
     * @param id
     */
    @Delete("delete from client where id = #{id}")
    void deleteClientById(Integer id);


    /**
     * 通过id对客户信息进行修改or充值
     * @param client
     */
    void editClientById(Client client);

    /**
     * 添加客户信息
     * @param client
     */
    void addClient(Client client);

    /**
     * 获取订单列表
     * @return
     */
    @Select("select * from `order`")
    List<Order> orderList();

    /**
     * 给食物添加销量
     * @param id
     * @param sales
     */
    @Update("update food set sales=sales+#{sales} where id=#{id} ")
    void addsales(Integer id, Integer sales);
}
